<template>
  <maincontainer class='flex flex-col'>
    <n-card title='基本信息'>
      <template #header-extra>
        <n-button text type='info' @click='getuserinfo'>
          <template #icon>
            <n-icon>
              <RefreshOutlined></RefreshOutlined>
            </n-icon>
          </template>
          刷新
        </n-button>
        <n-button text type='info' @click='edituserinfo'>
          <template #icon>
            <n-icon>
              <EditOutlined></EditOutlined>
            </n-icon>
          </template>
          编辑
        </n-button>
      </template>
      <descriptions :infoList='_userinfoList' :column='2'></descriptions>
    </n-card>
    <n-card title='教育信息'>
      <template #header-extra>
        <n-button text type='info' @click='geteducatdata'>
          <template #icon>
            <n-icon>
              <RefreshOutlined></RefreshOutlined>
            </n-icon>
          </template>
          刷新
        </n-button>
        <n-button text type='info' @click='addeducatinfo'>
          <template #icon>
            <n-icon>
              <PlusOutlined></PlusOutlined>
            </n-icon>
          </template>
          新增
        </n-button>
      </template>
      <flextable :column='educatcolumn' :tabledata='educattableData' :showctl='false'></flextable>
    </n-card>
    <n-card title='培训信息'>
      <template #header-extra>
        <n-button text type='info' @click='getetraindata'>
          <template #icon>
            <n-icon>
              <RefreshOutlined></RefreshOutlined>
            </n-icon>
          </template>
          刷新
        </n-button>
        <n-button text type='info' @click='addtraininfo'>
          <template #icon>
            <n-icon>
              <PlusOutlined></PlusOutlined>
            </n-icon>
          </template>
          新增
        </n-button>
      </template>
      <flextable :column='traincolumn' :tabledata='traintableData' :showctl='false'></flextable>
    </n-card>
    <n-card title='工作信息'>
      <template #header-extra>
        <n-button text type='info' @click='geteworkdata'>
          <template #icon>
            <n-icon>
              <RefreshOutlined></RefreshOutlined>
            </n-icon>
          </template>
          刷新
        </n-button>
        <n-button text type='info' @click='addworkinfo'>
          <template #icon>
            <n-icon>
              <PlusOutlined></PlusOutlined>
            </n-icon>
          </template>
          新增
        </n-button>
      </template>
      <flextable :column='workcolumn' :tabledata='worktableData' :showctl='false'></flextable>
    </n-card>
    <userinfoMdel ref='userinfoMdelref' @close='getuserinfo'></userinfoMdel>
    <workModel ref='workModelref' @close='geteworkdata'></workModel>
    <trainModel ref='trainModelref' @click='getetraindata'></trainModel>
    <educationModel ref='educationModelref' @close='geteducatdata'></educationModel>
  </maincontainer>
</template>

<script setup name='Userinfo' lang='ts'>
import {computed, inject, ref} from 'vue'
import userinfoMdel from './userinfoMdel.vue'
import workModel from './workModel.vue'
import trainModel from "./trainModel.vue"
import educationModel  from "./educatModel.vue"
import { PlusOutlined, EditOutlined } from '@vicons/antd'
import { RefreshOutlined } from '@vicons/material'
import { useListIndex } from '../../../hooks/useEdit'
import { useColumns } from '../../../hooks/useColumns'
import {useRouter,useRoute} from "vue-router"


const route = useRoute()
const { http, message } = useListIndex()
const { index, createdTime, changeTime, desc, view, edit, del } = useColumns()
/*******************************个人信息相关******************************************/
const userinfoloading = ref(false)
const userinfoMdelref = ref<any>(null)
const userinfotabledata = ref<any>({})
const userinfoList = ref([
  { label: '用户姓名', key: 'xingming', value: '' },
  { label: '用户ID', key: 'user', value: '' },
  { label: '民族', key: 'minzu', value: '' },
  { label: '籍贯', key: 'jiguan', value: '' },
  { label: '出生地', key: 'chushengdi', value: '' },
  { label: '政治面貌', key: 'zhengzhimianmao', value: '' },
  { label: '身高', key: 'shengao', value: '' },
  { label: '体重', key: 'tizhong', value: '' },
  { label: '参加工作时间', key: 'worktime', value: '' },
  { label: '最高学历', key: 'xueli', value: '' },
  { label: '身份证号', key: 'shenfenzheng', value: '' },
  { label: '联系地址', key: 'chushengdizhi', value: '' },
  { label: '所在地区', key: 'xianzaidizhi', value: '' },
  { label: '出生日期', key: 'chushengriqi', value: '' },
])
const _userinfoList = computed(() => {
  return userinfoList.value.map((item: any) => {
    return { ...item, value: userinfotabledata.value[item.key] }
  })
})

// 获取用户详细信息
const getuserinfo = () => {
  userinfoloading.value = true;
  http.getuserinfo({}).then(res => {
    userinfoloading.value = false
    if (res.data.code === 0) {
      userinfotabledata.value = res.data.data
      console.log(userinfotabledata.value, userinfotabledata.value.id, '怎么ID不见了')
    } else {
      message.error(res.data.error || '获取用户详细信息失败')
    }
  }).catch(()=>{
    userinfoloading.value = false
  })
}
// 点击编辑
const edituserinfo = () => {
  userinfoMdelref.value.init('edit', { ...userinfotabledata.value })
}
/*******************************教育相关******************************************/
const educationloading = ref(false)
const educationModelref=ref(null)
const educattableData = ref([]) // 教育信息数据
const educatcolumn = ref([
  index,
  { title: '学校名称', key: 'schoolname', width: 80, align: 'center', show: true },
  { title: '学历', key: 'level', width: 80, align: 'center', show: true },
  { title: '学制', key: 'xuezhi', width: 80, align: 'center', show: true },
  { title: '专业名称', key: 'zhuanye', width: 80, align: 'center', show: true },
  {
    title: '是否毕业',
    key: 'complete',
    width: 80,
    align: 'center',
    show: true,
    render: (rowData: any, rowIndex: number) => {
      return rowData['complete'] === '1' ? '毕业' : '肄业'
    },
  },
  {
    title: '开始时间',
    key: 'startTime',
    width: 80,
    align: 'center',
    show: true,
    render: (rowData: any, rowIndex: number) => {
      return new Date().toMyString(rowData['startTime'])
    },
  },
  {
    title: '结束时间', key: 'endTime', width: 80, align: 'center', show: true, render: (rowData: any, rowIndex: number) => {
      return new Date().toMyString(rowData['endTime'])
    },
  },
  view, edit, del,
])  // 教育信息字段
const geteducatdata = () => {
  educationloading.value = true
  http.liststudyinfo({}).then(res => {
    educationloading.value = false
    if (res.data.code === 0) {
      educattableData.value = res.data.items
    } else {
    }
  }).catch(()=>{
    educationloading.value = false
  })
}

const addeducatinfo=()=>{
  educationModelref.value.init("add")
}
/*******************************培训相关******************************************/
const trainloading = ref(false)
const trainModelref=ref(null)
const traintableData = ref([]) // 培训信息数据
const traincolumn = ref([
  index,
  { title: '学校名称', key: 'schoolname', width: 80, align: 'center', show: true },
  { title: '学校地址', key: 'schoolarea', width: 80, align: 'center', show: true },
  { title: '专业名称', key: 'zhuanye', width: 80, align: 'center', show: true },
  {
    title: '是否毕业',
    key: 'complete',
    width: 80,
    align: 'center',
    show: true,
    render: (rowData: any, rowIndex: number) => {
      return rowData['complete'] === '1' ? '毕业' : '肄业'
    },
  },
  {
    title: '开始时间',
    key: 'startTime',
    width: 80,
    align: 'center',
    show: true,
    render: (rowData: any, rowIndex: number) => {
      return new Date().toMyString(rowData['startTime'])
    },
  },
  {
    title: '结束时间', key: 'endTime', width: 80, align: 'center', show: true, render: (rowData: any, rowIndex: number) => {
      return new Date().toMyString(rowData['endTime'])
    },
  },
  view, edit, del,
])  // 培训信息字段
const getetraindata = () => {
  trainloading.value = true
  http.listpeixuninfo({}).then(res => {
    trainloading.value = false
    if (res.data.code === 0) {
      traintableData.value = res.data.items
    } else {
    }
  }).catch(()=>{
    trainloading.value = false
  })
}
// 增加培训信息
const addtraininfo=()=>{
  trainModelref.value.init("add")
}
/*******************************工作相关******************************************/
const workloading = ref(false)
const workModelref = ref<any>(null)
const worktableData = ref([]) // 工作信息数据
const workcolumn = ref([
  index,
  { title: '公司名称', key: 'companyname', width: 80, align: 'center', show: true },
  { title: '公司地址', key: 'companyarea', width: 80, align: 'center', show: true },
  { title: '职务', key: 'zhiwei', width: 80, align: 'center', show: true },
  { title: '职级', key: 'zhiji', width: 80, align: 'center', show: true },
  { title: '薪资', key: 'xinzi', width: 80, align: 'center', show: true },
  { title: '职责描述', key: 'desc', width: 80, align: 'center', show: true },
  { title: '证明联系人', key: 'contacts', width: 80, align: 'center', show: true },
  { title: '证明联系人电话', key: 'mobile', width: 80, align: 'center', show: true },
  {
    title: '开始时间',
    key: 'startTime',
    width: 80,
    align: 'center',
    show: true,
    render: (rowData: any, rowIndex: number) => {
      return new Date().toMyString(rowData['startTime'])
    },
  },
  {
    title: '结束时间', key: 'endTime', width: 80, align: 'center', show: true, render: (rowData: any, rowIndex: number) => {
      return new Date().toMyString(rowData['endTime'])
    },
  },
  view, edit, del,
])  // 工作信息字段
const geteworkdata = () => {
  workloading.value = true
  http.listworkinfo({}).then(res => {
    workloading.value = false
    if (res.data.code === 0) {
      worktableData.value = res.data.items
    } else {
    }
  }).catch(()=>{
    workloading.value = false
  })
}
// 增加工作信息
const addworkinfo=()=>{
  workModelref.value.init("add")
}

// 初始化函数
const init = () => {
  geteworkdata()
  getetraindata()
  geteducatdata()
  getuserinfo()
}
const zhucefunc:Function|undefined = inject("zhuceshuaxinfunc")
// 初始化区域
init()
zhucefunc && zhucefunc({[route.name!.toString()]:init})
</script>

<style scoped>

</style>